import {
  getSonComRequest,
  deteleSonComRequest,
  getProduceRequest,
  deteleProduceRequest
} from '@/service/sonCom/sonCom.js'

export default {
  state: {
    sonComList: [],
    produceList: []
  },
  mutations: {
    changeSC(state, sc) {
      state.sonComList = sc
    },
    changeProduce(state, sc) {
      state.produceList = sc
    }
  },
  actions: {
    async requestSonCom({ commit }) {
      const sonRes = await getSonComRequest()
      commit('changeSC', sonRes)
    },
    async requestProduce({ commit }) {
      const sonRes = await getProduceRequest()
      commit('changeProduce', sonRes)
    },
    async deteleRequestSonCom({ dispatch, commit }, scId) {
      await deteleSonComRequest({
        scId
      })
      dispatch('requestSonCom')
    },
    async deteleRequestProduce({ dispatch, commit }, pId) {
      await deteleProduceRequest({
        pId
      })
      dispatch('requestProduce')
    }
  }
}
